package com.zmj.base.file.service;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.List;

@Slf4j
@Service("fileService")
public class FileService {

    @Autowired
    List<IFileService> fileServices;

    @Autowired
    MinIoFileService minIoFileService;

    /**
     * 文件上传
     *
     * @return
     */
    public String saveItem(String parentPath, MultipartFile file) {
        return getFileService().saveItem(parentPath, file);
    }

    /**
     * 下载文件
     * @param url
     * @return
     */
    @SneakyThrows  //TODO
    public InputStream download(String url) {
        return getFileService().download(url);
    }

    /**
     * 删除文件
     * @param url
     * @return
     */
    public boolean deleteFile(String url) {
        return getFileService().deleteFile(url);
    }

    private IFileService getFileService() {
        return minIoFileService;
    }
}
